package com.regentsoft.cloudback.adapter;

import com.regentsoft.cloudback.enterpriseAdmin.util.AdminTokenManager;
import com.regentsoft.cloudback.interceptor.EnterpriseInterceptor;
import com.regentsoft.cloudback.interceptor.OperateInterceptor;
import com.regentsoft.cloudback.operateAdmin.util.SysAdminTokenManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.regentsoft.cloudback.interceptor.CORSInterceptor;
/**
 * 拦截器注册适配器
 * @author czd
 *
 * @date 2017年11月25日
 *
 * @version 1.0
 */
@Configuration
public class CustomWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter{
    private final AdminTokenManager tokenManager;
    private final SysAdminTokenManager sysAdminTokenManager;
    @Autowired
    public CustomWebMvcConfigurerAdapter(AdminTokenManager tokenManager,SysAdminTokenManager sysAdminTokenManager) {
        this.tokenManager = tokenManager;
        this.sysAdminTokenManager = sysAdminTokenManager;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new CORSInterceptor()).addPathPatterns("/manager/**").addPathPatterns("/api/**");  //对来自/manager/** 这个链接来的请求进行拦截
        registry.addInterceptor(new EnterpriseInterceptor(tokenManager))
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/company/login").excludePathPatterns("/api/screen/downloadResource").excludePathPatterns("/api/screen/getMediaInfo");
        registry.addInterceptor(new OperateInterceptor(sysAdminTokenManager)).addPathPatterns("/manager/**")
        .excludePathPatterns("/manager/admin/sysLogin")
        .excludePathPatterns("/manager/pdaMachineCode/**");
    }
}
